# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Josh Holbrook <josh.holbrook@gmail.com>

pkgname=python-pyee
pkgver=9.1.0
pkgrel=2
pkgdesc="Port of node.js's EventEmitter to python"
arch=('any')
url=https://github.com/jfhbrook/pyee
license=('MIT')
depends=('python-typing-extensions')
makedepends=('python-build' 'python-installer' 'python-setuptools'
             'python-wheel')
checkdepends=('python-pytest-asyncio' 'python-pytest-trio' 'python-twisted')
optdepends=('python-trio' 'python-twisted')
source=("https://files.pythonhosted.org/packages/source/p/pyee/pyee-$pkgver.tar.gz")
sha256sums=('a2287af31d6ce6e662ebf8034ea2c3e38dea02ebac63f6a41db23825bf6649d4')
b2sums=('8c011425d83c452f40451f152ed63994f4a76d424fefd1e4a69978ca8a0c4e55313269f93a102ea23b24b071270d3485a1cf0aa6aea911ed3e8a5648134ccbe3')

prepare() {
  cd pyee-$pkgver
  # Remove setup_requires list
  sed -i '/setup_requires/,/\],/d' setup.py
}

build() {
  cd pyee-$pkgver
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd pyee-$pkgver
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest
}

package() {
  cd pyee-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/pyee-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
